package com.example.myapplication.status;

/**
 *
 */
public class StatusContext {
    StatusView statusView;
    private Status status;

    public StatusContext() {
    }

    private Status getStatus() {
        if (null == status) {
            status = new StatusDownload(this);
        }
        return status;
    }

    private void setStatus(Status status) {
        this.status = status;
    }

    /**
     * 更新呢UI
     *
     * @param event
     */
    public void updateViewStatus(Event event) {
        String status = "";
        switch (event) {
            case DOWNLOAD:
                status = "下载中";
                break;
            case DOWNLOAD_FAILED:
                status = "下载失败";
                break;
            case INSTALL:
                status = "安装中";
                break;
            case INSTALL_FAILED:
                status = "安装失败";
                break;
            case OPEN:
                status = "打开";
                break;
            default:
                statusView.updateViewStatus(status);
        }
    }

    public void eventChange() {
        getStatus().doAction();
    }

    public void transfer(Event event) {
        switch (event) {
            case DOWNLOAD:
                setStatus(new StatusDownload(this));
                break;
            case DOWNLOAD_FAILED:
                setStatus(new StatusDownload(this));
                break;
            case INSTALL:
                setStatus(new StatusOpen(this));
                break;
            case INSTALL_FAILED:
                setStatus(new StatusInstall(this));
                break;
            case OPEN:
                statusView.open();
                break;
        }
    }

    /**
     * 此方法status子类调用
     *
     * @param event
     */
    public void doAction(Event event) {
        switch (event) {
            case DOWNLOAD:
//                presenter.download()
                break;
            case DOWNLOAD_FAILED:
                break;
            case INSTALL:
                break;
            case INSTALL_FAILED:
                break;
            case OPEN:
                statusView.open();
                break;
        }
    }

}
